scripts is a list of script records.
Each script record contains the following two fields:
1) Script id: The prefix "script_" will be inserted when referencing scripts.
2) Operation block: This must be a valid operation block. See header_operations.py for reference.
Some intro text here
hard-coded scripts, MadocComadrin, Modding Q&A
Not going into details, short description of content and linking to Tutorial and Code Example Sections
game_get_troop_wage : for weekly wage of troop
game_get_join_cost : for cost when joining
game_get_upgrade_cost : for cost of upgrading
etc.
Some special behaviour of game_get_skill_modifier_for_troop, cmpxchg8b, Modding Q&A and [WB] Warband Script Enhancer v3.2.0}
You have either noticed some scripts in module_scripts.py with the prefix cf_ or gotten some warning at compiling your module with the following content:
WARNING: Script can fail at operation #x. Use cf_ at the beginning of its name: some_script_name
The prefix cf_ indicates a script that can fail. MaBL/MBScript requires that every command (line) is true or it jumps to the next block (scope). cf_-scripts are a handy way to use this:[1]
top level scope
| second level scope
|
(try_begin)
(call_script, "cf_something"), # goes to line 2 (true) or 4 (false)
(assign, ":true", 1),
(display_message, "@ololol"),
(else_try),
(assign, ":true", 0), # if cf_ fails (is false)
(try_end),
You can read the warning as a recommendation, since you have a conditional operation that would cause the script to fail within the top level scope of the script rather than inside a try block. Therefore, if that operation causes the script to fail, the scope where the call_script operation calls this script would also fail.[2] cf_-scripts are usually used as complex conditionals, you can use them to write your own conditional functions.[3]
To give a short example for a complex conditional: cf_-script can be used as a part of a this_or_next operation:
Example 1:
(this_or_next|eq, 1, 0),
(call_script, "script_cf_eq_1_1"),
Example 2:
(this_or_next|call_script, "script_cf_eq_1_1"),
(eq, reg1, 0),
Example 1 will work as a cf_-script can be used as the last case. Example 2 on the contrary does not work as intended, it just fails or continues as with a normal call_script operation.[4]
Coming back to the warning message mentioned above. Two ways have been now indicated on how to deal with it. The first option is to add the prefix cf_ infront of the script name, not because you simply want the warning message to disappear but because you understood the effect of it and how this script might affect your work. The second option is nearly as simple: If you don't want your script to behave like a can-fail one, wrap the entire script code between try_begin} and try_end.[5]
Scripts called by the game engine are getting read top to bottom, so only the first script will be called in case there are numerous scripts with the same name. The script numeric ID is getting created at the compilation: the compiler loops through all scripts, starting from the first script (with the numerical ID 0), and compares the script identifier for which we are looking ("script_abcd") with each script's string id. Once one occurrence is found, the numeric id of that script is returned, so the search stops and will never return the second or third occurrence of a script.[6]
Recheck this one, perhaps useful info, RecursiveHarmony (credit), Script file unknown float variable